import { getProfileDataOf, getTop10CostyMethods } from '@/utils/decorators';
import { $renderNumber, $render } from '@/utils/logger';
import { register, reject } from './api';

register('profiler', (mode: string, args: string[]) => {
    if (mode === 'get') {
        const data = getProfileDataOf(args[0]);
        if (data) {
            return `函数 ${args[0]} 的性能数据：总调用次数 ${data.totalCallTimes}，总耗时 ${data.totalExecuteTime}ms，平均耗时 ${data.averageExecuteTime}ms (${$renderNumber(data.percentage)}%)`;
        }
        else {
            return $render('找不到性能分析信息', ConsoleColor.red);
        }
    }
    else if (mode === 'top') {
        return getTop10CostyMethods().join('  ');
    }
    else {
        return reject();
    }
});